using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DAL
{
    public class StoredProcedures
    {
        private MainDB _db;

        public StoredProcedures(MainDB db)
        {
            _db = db;
        }

        public MainDB Database
        {
            get { return _db; }
        }

        protected DataSet CreateDataSet(IDbCommand command)
        {
            return _db.CreateDataSet(command);
        }

        protected DataTable CreateDataTable(IDbCommand command)
        {
            return _db.CreateDataTable(command);
        }

        public DataTable GetCurrentRound()
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_GetCurrentRound", true);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable BoxDatGia(int top, int round, int awardId, int pageIndex, int pageSize)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_BoxDatGia", true);                                                                                                                                                              
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "AwardsID", DbType.Int32, awardId);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }
        public DataTable BoxDatGia_Cont(int top, int round, int awardId, string ImageIds, int pageIndex, int pageSize)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_BoxDoatGiai_Cont", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "AwardsID", DbType.Int32, awardId);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "ImageIds", DbType.String, ImageIds);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable BoxMoiNhat(int top, int round, int awardId, int pageIndex, int pageSize)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_BoxMoiNhat", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "AwardsID", DbType.Int32, awardId);
            _db.AddParameter(cmd, "RoundAwards", DbType.Int32, round);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }
        public DataTable BoxMoiNhat_Cont(int top, int round, int awardId, string ImageIds, int pageIndex, int pageSize)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_BoxMoiNhat_Cont", true);
            _db.AddParameter(cmd, "Top", DbType.Int32, top);
            _db.AddParameter(cmd, "AwardsID", DbType.Int32, awardId);
            _db.AddParameter(cmd, "RoundAwards", DbType.Int32, round);
            _db.AddParameter(cmd, "ImageIds", DbType.String, ImageIds);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }
        public DataTable Search(string keySearch, int round, int awardId, int pageIndex, int pageSize)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_Search", true);
            _db.AddParameter(cmd, "KeySearch", DbType.String, keySearch);
            _db.AddParameter(cmd, "AwardsID", DbType.Int32, awardId);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable SearchCount(string keySearch, int round, int awardId)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_SearchCount", true);
            _db.AddParameter(cmd, "KeySearch", DbType.String, keySearch);
            _db.AddParameter(cmd, "AwardsID", DbType.Int32, awardId);
            _db.AddParameter(cmd, "Round", DbType.Int32, round);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable SearchXemBinhChon(string keySearch, string startDate, string endDate, int pageIndex, int pageSize)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_SearchXemBinhChon", true);
            _db.AddParameter(cmd, "KeySearch", DbType.String, keySearch);
            _db.AddParameter(cmd, "StartDate", DbType.String, startDate);
            _db.AddParameter(cmd, "EndDate", DbType.String, endDate);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable SearchXemBinhChonCount(string keySearch, string startDate, string endDate)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_SearchCountXemBinhChon", true);
            _db.AddParameter(cmd, "KeySearch", DbType.String, keySearch);
            _db.AddParameter(cmd, "StartDate", DbType.String, startDate);
            _db.AddParameter(cmd, "EndDate", DbType.String, endDate);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable SearchXemBinhChon_NoDateTime(string keySearch, int pageIndex, int pageSize)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_SearchXemBinhChon_NoDateTime", true);
            _db.AddParameter(cmd, "KeySearch", DbType.String, keySearch);
            _db.AddParameter(cmd, "PageIndex", DbType.Int32, pageIndex);
            _db.AddParameter(cmd, "PageSize", DbType.Int32, pageSize);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable SearchXemBinhChonCount_NoDateTime(string keySearch)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_SearchCountXemBinhChon_NoDateTime", true);
            _db.AddParameter(cmd, "KeySearch", DbType.String, keySearch);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable InsertImage(string acc, string Name, string Search, string Email, string Address, string Phone, string Other, string Img, string Title, string ShortContent, string LongContent, int RoundAward, string Birthday, string linkFB)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_InsertImage", true);
            _db.AddParameter(cmd, "acc", DbType.String, acc);
            _db.AddParameter(cmd, "Name", DbType.String, Name);
            _db.AddParameter(cmd, "Search", DbType.String, Search);
            _db.AddParameter(cmd, "Email", DbType.String, Email);
            _db.AddParameter(cmd, "Address", DbType.String, Address);
            _db.AddParameter(cmd, "Phone", DbType.String, Phone);
            _db.AddParameter(cmd, "Other", DbType.String, Other);
            _db.AddParameter(cmd, "Img", DbType.String, Img);
            _db.AddParameter(cmd, "Title", DbType.String, Title);
            _db.AddParameter(cmd, "ShortContent", DbType.String, ShortContent);
            _db.AddParameter(cmd, "LongContent", DbType.String, LongContent);
            _db.AddParameter(cmd, "RoundAwards", DbType.Int32, RoundAward);
            _db.AddParameter(cmd, "birthday", DbType.String, Birthday);
            _db.AddParameter(cmd, "linkfb", DbType.String, linkFB);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }

        public DataTable UpdateVote(int ImageId)
        {
            IDbCommand cmd = _db.CreateCommand("aigiongia_UpdateVote", true);
            _db.AddParameter(cmd, "ImageId", DbType.String, ImageId);
            DataTable __dt = CreateDataTable(cmd);
            return __dt;
        }
    }
}
